Xbasic
Array filter Method
Syntax
V <array>.filter(expression as C [, exclude as L])
Arguments
- expressionCharacter
An Xbasic expression that evaluates to true or false. The expression can reference properties of the property array directly. See example below.
- excludeLogical
Default = .f. (keep). If .t., all values that match the expression will be removed from the array. If .f., all values that match the expression will be kept in the array.
Description
Removes entries from a property array that match or do not match a filter expression.
Discussion
The <array>.filter() method can be used to delete or keep entries in a property array that match a filter. This method only supports property arrays.
Example
dim a[50] as P for i = 1 to 50 a[i].num = round(rand()*100,0) a[i].randString = chr(rand()*100) next ' define a filter expression that compares the value of ' "randString"" property for every array element to make ' sure it is between chr(31) and chr(127) dim expression = "randString <= chr(31) .or. randString >= chr(127)" ' remove all elements that match the expression a.filter(expression,.t.) ? a.dump_properties("randString: num") = ^: 47 W: 46 C: 41 E: 49 Q: 25 /: 77 W: 57 Q: 99 E: 49 3: 1 V: 41 <: 86 W: 39 %: 45 8: 11 0: 41 5: 1 9: 85 @: 10 B: 98 c: 13 (: 37 [: 48 O: 85 I: 90 /: 13 %: 93 X: 23 ]: 49 B: 25 a: 89 2: 76 S: 80 D: 69 P: 14 Y: 42 `: 65 I: 69